<template >
  <button class="gin-switch" :class="{checked: value}" :disabled='disabled' @click="toggleFlag">
    <span></span>
  </button>
  <div>{{value}}</div>
</template>

<script lang="ts">
export default {
  props: {
    value: {
      type: Boolean
    },
    disabled: {
      type: Boolean
    }
  },
  setup(props, ctx) {
    const toggleFlag = () => {
      ctx.emit('update:value', !props.value)
    }
    return {
      toggleFlag
    }
  }
}
</script>


<style lang="scss" >
$h: 22px;
$h2: $h - 4px;
.gin-switch {
  height: $h;
  width: $h*2;
  border: none;
  background: #bfbfbf;
  border-radius: calc($h/2);
  position: relative;
  > span{
    position: absolute;
    top: 2px;
    left: 2px;
    height: $h2;
    width: $h2;
    background:white;
    border-radius: 50%;
    transition: all .25s;
  } 
  &.checked  {
    background: #1890ff;
    > span {
    left: calc(100% - #{$h2} - 2px);
    }
  }

  &:focus {
    outline: none;
  }
  &:active{
    > span {width: $h2 + 4px;}
  }
  &.checked:active{
    > span {width: $h2 + 4px; margin-left: -4px;}
  }
}

</style>